package com.xudu.config;

import com.xudu.entity.User;
import com.xudu.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class AdminUserInitializer {

    @Autowired
    private IUserService iUserService;

    @PostConstruct
    public void init() {
        User adminUser = User.builder()
                .username("admin")
                .password("admin")
                .role(1)
                .build();
        boolean b = iUserService.findUserByUsername(adminUser);
        if (!b) {
            iUserService.createUser(adminUser); // 设置初始管理员账号和密码
            System.out.println("超级管理员账号初始化完成.");
        }else {
            System.out.println("超级管理员账号已存在！");
        }
    }
}